package com.gadgets.framework.sequeuce.controller;

import com.gadgets.framework.common.dto.HttpBaseResp;
import com.gadgets.framework.common.dto.Pagination;
import com.gadgets.framework.common.exception.GadgetsServiceException;
import com.gadgets.framework.common.pojo.Sequeuce;
import com.gadgets.framework.sequeuce.dto.SequeuceQueryDTO;
import com.gadgets.framework.sequeuce.dto.SequeuceResetDTO;
import com.gadgets.framework.sequeuce.service.ISequeuceManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2021-06-03
 * @moduel gadgets
 * 
 */
@RestController
@RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/manage/sequeuce")
public class SequeuceManageController {

    @Autowired
    @Qualifier(value = "sequeuceManageServiceImpl")
    private ISequeuceManageService sequeuceManageService;

    /**
     * 获取序列信息
     * @param request                       请求信息
     * @param response                      应答信息
     * @param queryDTO                      查询条件
     * @param pagination                    分页条件
     * @return                              查询结果
     * @throws GadgetsServiceException      异常信息
     */
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/querySeque.do")
    //@RoleAuthCheck(userType = GadgetsConstant.USER_TYPE.SYS_MANAGER)
    public HttpBaseResp<Sequeuce> getSequeuceInfoByCondition(HttpServletRequest request, HttpServletResponse response, SequeuceQueryDTO queryDTO, Pagination pagination) throws GadgetsServiceException{
        queryDTO.addDesc("SEQ_NAME");
        return new HttpBaseResp<Sequeuce>(sequeuceManageService.querySequeuceInfo(queryDTO, pagination),pagination);
    }

    /**
     * 重置指定序列信息
     * @param request                       请求信息
     * @param response                      应答信息
     * @param resetDTO                      重置信息
     * @return                              通用应答
     * @throws GadgetsServiceException      异常信息
     */
    @SuppressWarnings("rawtypes")
    //@RoleAuthCheck(userType = GadgetsConstant.USER_TYPE.SYS_MANAGER)
    @RequestMapping(method = {org.springframework.web.bind.annotation.RequestMethod.POST,org.springframework.web.bind.annotation.RequestMethod.GET},value = "/reset.do")
    public HttpBaseResp resetSequeueInfo(HttpServletRequest request, HttpServletResponse response, SequeuceResetDTO resetDTO) throws GadgetsServiceException{
        sequeuceManageService.resetSequeuce(resetDTO);
        return new HttpBaseResp();
    }

}
